$(function () {
    layui.form.verify({
        pwd: [/^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'],
        diffPwd: function (value, item) {
            if (value == $('[name="oldPwd"]').val()) {
                return "新旧密码不能一样"
            }
        },
        rePwd: function (value, item) {
            if (value != $('[name="newPwd"]').val()) {
                return "两次新密码不一致"
            }
        }

    })

    $('#form1').submit(function (e) {
        e.preventDefault();
        $.ajax({
            method: 'POST',
            url: '/my/updatepwd',
            data: $(this).serialize(),
            success: function (res) {
                if (res.status != 0) return layui.layer.msg('更新密码失败！')
                layui.layer.msg('更新密码成功！')
                localStorage.removeItem('token')
                window.parent.location.href = '/login.html'
            }
        })
    })
})